
package de.justphil.tcg.tcgandroidclient.network.rest;

import org.json.JSONException;
import org.json.JSONObject;

public class RESTEncoder {
	
	public static String encodeJoinGameRq(long deckId) {
	
		return encodeGameRq(deckId);
	}
	
	public static String encodeCreateGameRq(long deckId) {
	
		return encodeGameRq(deckId);
	}
	
	private static String encodeGameRq(long deckId) {
	
		if (deckId <= 0) {
			throw new IllegalArgumentException("The deckId must not be <= 0");
		}
		JSONObject resultJson = new JSONObject();
		try {
			resultJson.put("deckId", deckId);
			return resultJson.toString();
		}
		catch (JSONException e) {
			throw new RuntimeException("Could not encode CreateGameRq: " + e.getMessage());
		}
	}

	public static String encodeFoundRq(String hash) {
	
		if (hash == null) {
			throw new IllegalArgumentException("The deckId must not be <= 0");
		}
		JSONObject resultJson = new JSONObject();
		try {
			resultJson.put("hash", hash);
			return resultJson.toString();
		}
		catch (JSONException e) {
			throw new RuntimeException("Could not encode FoundRq: " + e.getMessage());
		}
	}
}
